package demo2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-07-25
 * Time: 14:23
 */
public class TestDemo {

    public static boolean flg = false;

    public static void main(String[] args) {
        Thread t = new Thread(()->{
           while(!flg){
               try {
                   System.out.println("我是Thread");
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        });

        t.start();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("使用flg标记法开始中断Thread线程");
        flg = true;

    }


}
